import requests
import jsonpath
import json
import allure
import pymysql
class  Apikey:
    @allure.step("返回结果")
    def get_text(self,data,key):
        dict_data=json.load(data)
        value=jsonpath.jsonpath(dict_data,key)
        return value[0]
    @allure.step("返回get请求")
    def get(self,url,params,**kwargs):
        return requests.get(url=url,params=params,**kwargs)
    @allure.step("返回post请求")
    def post(self,url,params,**kwargs):
        return requests.post(url=url,params=params,**kwargs)
    #数据库检查关键字
    @allure.step("数据库检查")
    def sqlcheck(self,sql):
    #1建立连接
        conn=pymysql.connect(
            host='shop-xo.hctestedu.com',
            port=3306,
            user='api_test',
            passwd='Aa9999!',
            database='shopxo_hctested',
            charset='utf8')
        cmd=conn.cursor()#创建游标
        cmd.execute(query=sql)#准备执行sql语句
        result=cmd.fetchall()#查询结果
        conn.close()#关闭游标
        return result

if __name__=='__main__':
    ak=Apikey()
    data = {"accounts":"zz","pwd":"123456","type": "username"}
    params={"application": "app",
     "application_client_type": "weixin"
            }
    res=ak.post(url='http://shop-xo.hctestedu.com/index.php?s=api/user/login',json=data,params=params)
    print(res.text)

